package cn.kshost.zqyg.manager.controller;

import cn.hutool.core.util.StrUtil;
import cn.kshost.zqyg.manager.service.SysUserRoleService;
import cn.kshost.zqyg.model.dto.system.AssginRoleDto;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysUserRole")
public class SysUserRoleController {

    @Autowired
    SysUserRoleService sysUserRoleService;
    @Operation(summary = "给用户分配权限")
    @PostMapping("/assignRoleToUser")
    public Result assignRoleToUser(@RequestBody AssginRoleDto assginRoleDto){
        sysUserRoleService.assignRoleToUser(assginRoleDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据userId查询所有关联的roleId")
    @GetMapping("/getRoleIdsByUserId")
    public Result<List<Long>> getRoleIdsByUserId(@RequestParam("userId") Long userId){
        List<Long>  roleIds =  sysUserRoleService.getRoleIdsByUserId(userId);
        return Result.build(roleIds, ResultCodeEnum.SUCCESS);
    }
}
